package com.vogue.supplymall.order.domain.dao.impl;

import com.vogue.supplymall.order.domain.dao.OrderBuyerDao;
import com.vogue.supplymall.order.domain.mapper.OrderBuyerMapper;
import com.vogue.supplymall.order.domain.model.OrderBuyer;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * The type Order buyer dao.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-10
 */
@Repository("orderBuyerDao")
public class OrderBuyerDaoImpl extends BaseDaoImpl<OrderBuyer, Long> implements OrderBuyerDao {
    @Resource
    private OrderBuyerMapper orderBuyerMapper;

    @Override
    public String getSqlByWhere(OrderBuyer orderBuyer) {
        StringBuilder where = new StringBuilder()
                .append(" where ")
                .append(" syscodeid = ")
                .append(orderBuyer.getSyscodeid())
                .append(" AND organid = ")
                .append(orderBuyer.getOrganid())
                .append(" AND userid = ")
                .append(orderBuyer.getUserid())
                // 2018/6/21 检索出最早的买家信息，即购物车买家
                .append(" ORDER BY createdate ");
        return where.toString();
    }

    @Override
    public OrderBuyer searchOrderBuyer(OrderBuyer orderBuyer) {
        List<OrderBuyer> lists = orderBuyerMapper.searchOrderBuyer(orderBuyer);
        return (null == lists) ? null : lists.get(0);
    }
}
